

#import "ViewController.h"
#import "fishhook.h"

@interface ViewController ()

@end

@implementation ViewController

// ----- hook C 函数-----
void func(const char * str){
    NSLog(@"%s",str);
}

// 函数指针
static void(*old_func)(const char * str);

//定义一个新的函数
void new_func(const char * str){
    NSLog(@"%s + 1",str);
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor lightGrayColor];
    
//    NSLog(@"测试1");
//    NSLog(@"测试1");
    
     //rebinding结构体
     struct rebinding nslog;
     nslog.name = "NSLog";
     nslog.replacement = new_func;
     nslog.replaced = (void *)&old_func;

     //rebinding结构体数组
     struct rebinding rebs[1] = {nslog};
     /**
      * 存放rebinding结构体的数组
      * 数组的长度
      */
     rebind_symbols(rebs, 1);
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"点击了屏幕");
//    func("哈哈啊哈哈");
    
}

@end
